//
//  GlobalFunction.m
//  AmountBody
//
//  Created by smm on 17/12/6.
//  Copyright (c) 2017年 RCMTM. All rights reserved.
//

#import "GlobalFunction.h"
#import "CommonCrypto/CommonDigest.h"

void layoutViews(VoidBlock landscape, VoidBlock portrait) {
    if (SCREEN_W > SCREEN_H) { //横屏
        if (landscape) {
            landscape();
        }
    } else {
        if (portrait) {
            portrait();
        }
    }
}


@implementation GlobalFunction

#pragma mark - 基本方法
#pragma mark - 正则验证
//封装一个执行正则验证的方法，传入一个正则表达式和一个需要的验证的值就会返回是否通过的结果
+(BOOL)regex_match:(NSString *)regex andValue:(NSString *)value
{
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    return [pred evaluateWithObject:value];
}

+(BOOL)anotherRegex_match:(NSString *)regexStr andValue:(NSString *)value
{
    NSError *error;
    //http+:[^\\s]* 这是检测网址的正则表达式
    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regexStr options:0 error:&error];
    
    if (regex != nil) {
        NSTextCheckingResult *firstMatch = [regex firstMatchInString:value options:0 range:NSMakeRange(0, [value length])];
        
        if (firstMatch) {
            return YES;
        }
    }
    return NO;
}

#pragma mark -- 状态栏显示或隐藏加载圈
+(void)shownetActivityindicator
{
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
}

+(void)hidenetActivityindicator
{
    [UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}

#pragma mark -- Object 转 jsonstring
+(NSDictionary *)globalObjectToJSONStringWithObject:(NSString*)object
{
    NSData *JSONData = [object dataUsingEncoding:NSUTF8StringEncoding];
    NSDictionary *responseJSON = [NSJSONSerialization JSONObjectWithData:JSONData options:NSJSONReadingMutableLeaves error:nil];
    return responseJSON;
}

@end
